#ifndef CUSTOMNUMEDIT_H
#define CUSTOMNUMEDIT_H

#include <QWidget>

namespace Ui {
class CustomNumEdit;
}

class CustomLineEdit;
class CustomNumEdit : public QWidget
{
    Q_OBJECT

public:
    explicit CustomNumEdit(QWidget *parent = Q_NULLPTR);
    virtual ~CustomNumEdit();

    void init(double min, double max, int decimals, bool allowEmpty);
    void init(double min, double max, double defaultValue, int decimals);
    void init(double min, double max, int defaultValue);

    double value() const;
    double setValue(double value);

    QString placeholderText() const;
    void setPlaceholderText(const QString &);

    QString text() const;

    bool setProperty(const char *name, const QVariant &value);
    QVariant property(const char *name) const;

Q_SIGNALS:
    void lostFocus();

public:
    void setText(const QString &);
    void clear();
    void setFocus();
    void selectAll();

protected Q_SLOTS:
    void onTextChanged();
    void onFocusIn();
    void onFocusOut();

private:
    void initUi();

private:
    Ui::CustomNumEdit *ui;
    CustomLineEdit *m_numEdit;
    double m_value;
    double m_defaultValue;
    double m_min;
    double m_max;
    int m_decimals;
    bool m_allowEmpty;
};

#endif // CUSTOMNUMEDIT_H
